/*
    RExLib project - RVector_Example, file main.cpp
    Copyright (C) 2012  Sarvaritdinov Ravil ra9oaj@gmail.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <iostream>
#include <cstdio>
#include <ctime>
#include <vector>
#include "../../core/rvector.h"

using namespace std;
using namespace rex;

void RVectorTest ( int size )
{
    RVector<int> lst;

    printf ( "Inserting %d elements in RVector\r\n",size );
    clock_t tStart;
    tStart = std::clock();
    for ( int i = 0; i < size; ++i )
    {
        lst.insert(i);
    }
    printf ( "Done! Time: %.3f s\r\n", ( float ) ( std::clock() - tStart ) / CLOCKS_PER_SEC );

    printf ( "Getting %d elements from RVector\r\n",size );
    tStart = std::clock();
    for ( int i = 0; i < lst.size(); ++i )
        lst.value ( i );

    printf ( "Done! Time: %.3f secn\r\n", ( float ) ( std::clock() - tStart ) / CLOCKS_PER_SEC );

    printf ( "Deleting %d elements from RVector\r\n",size );
    tStart = std::clock();
    lst.clear();

    printf ( "Done! Time: %.3f secn\r\n\r\n", ( float ) ( std::clock() - tStart ) / CLOCKS_PER_SEC );
}

void STLVector ( int size )
{
    vector<int> lst;

    printf ( "Inserting %d elements in vector\r\n",size );
    clock_t tStart;
    tStart = std::clock();
    for ( int i = 0; i < size; ++i )
    {
        lst.push_back ( i );
    }
    printf ( "Done! Time: %.3f s\r\n", ( float ) ( std::clock() - tStart ) / CLOCKS_PER_SEC );

    printf ( "Getting %d elements from vector\r\n",size );
    tStart = std::clock();
    for ( vector<int>::iterator it = lst.begin(); it != lst.end(); ++it )
        *it;
    printf ( "Done! Time: %.3f secn\r\n", ( float ) ( std::clock() - tStart ) / CLOCKS_PER_SEC );

    printf ( "Deleting %d elements from vector\r\n",size );
    tStart = std::clock();
    lst.clear();

    printf ( "Done! Time: %.3f secn\r\n\r\n", ( float ) ( std::clock() - tStart ) / CLOCKS_PER_SEC );
}

int main ( int argc, char *argv[] )
{
    RVectorTest ( 1000 );
    RVectorTest ( 10000 );
    RVectorTest ( 100000 );
    RVectorTest ( 1000000 );
    RVectorTest ( 2000000 );
    printf ( "============= STL =============\r\n" );

    STLVector ( 1000 );
    STLVector ( 10000 );
    STLVector ( 100000 );
    STLVector ( 1000000 );
    STLVector ( 2000000 );

    return 0;
}
